// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.randomizedWorld.randomizedVehicleStory;

import zombie.core.Rand;
import zombie.iso.IsoCell;
import zombie.iso.IsoChunk;
import zombie.iso.IsoDirections;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoMetaGrid;
import zombie.iso.IsoObject;
import zombie.iso.Vector2;
import zombie.vehicles.BaseVehicle;
import zombie.vehicles.VehiclePart;

public final class RVSPoliceBlockadeShooting extends RandomizedVehicleStoryBase {
    public RVSPoliceBlockadeShooting() {
        this.name = "Police Blockade Shooting";
        this.minZoneWidth = 8;
        this.minZoneHeight = 8;
        this.setChance(1);
        this.setMaximumDays(30);
    }

    @Override
    public boolean isValid(IsoMetaGrid.Zone zone, IsoChunk chunk, boolean force) {
        boolean _boolean = super.isValid(zone, chunk, force);
        return !_boolean ? false : zone.isRectangle();
    }

    @Override
    public void randomizeVehicleStory(IsoMetaGrid.Zone zone, IsoChunk chunk) {
        this.callVehicleStorySpawner(zone, chunk, 0.0F);
    }

    @Override
    public boolean initVehicleStorySpawner(IsoMetaGrid.Zone zone, IsoChunk chunk, boolean debug) {
        VehicleStorySpawner vehicleStorySpawner = VehicleStorySpawner.getInstance();
        vehicleStorySpawner.clear();
        float float0 = (float) (Math.PI / 18);
        if (debug) {
            float0 = 0.0F;
        }

        float float1 = 1.5F;
        float float2 = 1.0F;
        if (this.zoneWidth >= 10) {
            float1 = 2.5F;
            float2 = 0.0F;
        }

        boolean _boolean = Rand.NextBool(2);
        if (debug) {
            _boolean = true;
        }

        IsoDirections isoDirections = Rand.NextBool(2) ? IsoDirections.W : IsoDirections.E;
        Vector2 vector2 = isoDirections.ToVector();
        vector2.rotate(Rand.Next(-float0, float0));
        vehicleStorySpawner.addElement("vehicle1", -float1, float2, vector2.getDirection(), 2.0F, 5.0F);
        vector2 = isoDirections.RotLeft(4).ToVector();
        vector2.rotate(Rand.Next(-float0, float0));
        vehicleStorySpawner.addElement("vehicle2", float1, -float2, vector2.getDirection(), 2.0F, 5.0F);
        vehicleStorySpawner.addElement(
            "barricade", 0.0F, _boolean ? -float2 - 2.5F : float2 + 2.5F, IsoDirections.N.ToVector().getDirection(), (float)this.zoneWidth, 1.0F
        );
        int int0 = Rand.Next(7, 15);

        for (int int1 = 0; int1 < int0; int1++) {
            vehicleStorySpawner.addElement(
                "corpse",
                Rand.Next((float)(-this.zoneWidth) / 2.0F + 1.0F, (float)this.zoneWidth / 2.0F - 1.0F),
                _boolean ? (float)Rand.Next(-7, -4) - float2 : (float)Rand.Next(5, 8) + float2,
                IsoDirections.getRandom().ToVector().getDirection(),
                1.0F,
                2.0F
            );
        }

        String string = "Base.CarLightsPolice";
        if (Rand.NextBool(3)) {
            string = "Base.PickUpVanLightsPolice";
        }

        vehicleStorySpawner.setParameter("zone", zone);
        vehicleStorySpawner.setParameter("script", string);
        return true;
    }

    @Override
    public void spawnElement(VehicleStorySpawner spawner, VehicleStorySpawner.Element element) {
        IsoGridSquare isoGridSquare0 = element.square;
        if (isoGridSquare0 != null) {
            float float0 = element.z;
            IsoMetaGrid.Zone zone = spawner.getParameter("zone", IsoMetaGrid.Zone.class);
            String string0 = spawner.getParameterString("script");
            String string1 = element.id;
            switch (string1) {
                case "barricade":
                    if (this.horizontalZone) {
                        int int0 = (int)(element.position.y - element.width / 2.0F);
                        int int1 = (int)(element.position.y + element.width / 2.0F) - 1;
                        int int2 = (int)element.position.x;

                        for (int int3 = int0; int3 <= int1; int3++) {
                            IsoGridSquare isoGridSquare1 = IsoCell.getInstance().getGridSquare(int2, int3, zone.z);
                            if (isoGridSquare1 != null) {
                                if (int3 != int0 && int3 != int1) {
                                    isoGridSquare1.AddTileObject(IsoObject.getNew(isoGridSquare1, "construction_01_9", null, false));
                                } else {
                                    isoGridSquare1.AddTileObject(IsoObject.getNew(isoGridSquare1, "street_decoration_01_26", null, false));
                                }
                            }
                        }
                    } else {
                        int int4 = (int)(element.position.x - element.width / 2.0F);
                        int int5 = (int)(element.position.x + element.width / 2.0F) - 1;
                        int int6 = (int)element.position.y;

                        for (int int7 = int4; int7 <= int5; int7++) {
                            IsoGridSquare isoGridSquare2 = IsoCell.getInstance().getGridSquare(int7, int6, zone.z);
                            if (isoGridSquare2 != null) {
                                if (int7 != int4 && int7 != int5) {
                                    isoGridSquare2.AddTileObject(IsoObject.getNew(isoGridSquare2, "construction_01_8", null, false));
                                } else {
                                    isoGridSquare2.AddTileObject(IsoObject.getNew(isoGridSquare2, "street_decoration_01_26", null, false));
                                }
                            }
                        }
                    }
                    break;
                case "corpse":
                    BaseVehicle baseVehicle1 = spawner.getParameter("vehicle1", BaseVehicle.class);
                    if (baseVehicle1 != null) {
                        createRandomDeadBody(element.position.x, element.position.y, (float)zone.z, element.direction, false, 10, 10, null);
                        IsoDirections isoDirections = this.horizontalZone
                            ? (element.position.x < baseVehicle1.x ? IsoDirections.W : IsoDirections.E)
                            : (element.position.y < baseVehicle1.y ? IsoDirections.N : IsoDirections.S);
                        float float1 = isoDirections.ToVector().getDirection();
                        this.addTrailOfBlood(element.position.x, element.position.y, element.z, float1, 5);
                    }
                    break;
                case "vehicle1":
                case "vehicle2":
                    BaseVehicle baseVehicle0 = this.addVehicle(
                        zone, element.position.x, element.position.y, float0, element.direction, null, string0, null, null
                    );
                    if (baseVehicle0 != null) {
                        spawner.setParameter(element.id, baseVehicle0);
                        if (Rand.NextBool(3)) {
                            baseVehicle0.setHeadlightsOn(true);
                            baseVehicle0.setLightbarLightsMode(2);
                            VehiclePart vehiclePart = baseVehicle0.getBattery();
                            if (vehiclePart != null) {
                                vehiclePart.setLastUpdated(0.0F);
                            }
                        }

                        String string2 = "PoliceRiot";
                        Integer integer = 0;
                        this.addZombiesOnVehicle(Rand.Next(2, 4), string2, integer, baseVehicle0);
                    }
            }
        }
    }
}
